import {WidgetClass} from "./widget";

// 设备小组件
export class WidgetDevice extends WidgetClass {
  constructor(options = {}) {
    super(options);
    const {ports, UI} = options;
    if (UI) {
      this.UI.data = UI.data;
    } else {
      this.UI.data = {
        widgetSize: {

          rows: 1,
          columns: 1,
        },
        widgetPosition: {
          row: 0,
          column: 0
        },
        detailPage:{}
      };
    }
    if (ports) {
      this.ports = ports;
    } else {
      this.ports = this.assembleDefaultPorts();
    }
  }

  assembleDefaultPorts() {
    const superState = super.assembleDefaultPorts();
    return {
      values: [
        ...superState.values,
        {
          name: "显示详情页",
          key: "showDetail",
          type: "bool",
          value: false,
        },
      ],
      events: [
        {
          name: "抬起事件",
          key: `onTap-${this.id}`,
          eventType: "onTap",
          type: "event",
          action: [],
        },
        {
          name: "按下事件",
          key: `tapDown-${this.id}`,
          type: "event",
          eventType: "tapDown",
          action: [],
        },
        {
          name: "长按事件",
          key: `longPress-${this.id}`,
          eventType: "longPress",
          type: "event",
          value: {
            time: 1 //长按触发时间(秒)
          },
          action: [],
        },
        // {
        //   name: "设备状态变化",
        //   key: `valueChange-${this.id}`,
        //   eventType: "valueChange",
        //   type: "event",
        //   action: [],
        // }
      ],
    };
  }
}
